package fairygui.editor.publish.gencode
{
   import fairygui.editor.utils.UtilsFile;
   import flash.filesystem.File;
   
   public class GenTypeScript extends GenerateCodeBase
   {
       
      
      public function GenTypeScript()
      {
         super();
      }
      
      override public function run() : void
      {
         init("ts");
         loadTemplate("TypeScript");
      }
      
      override protected function createFile(param1:*) : void
      {
         var _loc3_:* = null;
         var _loc4_:String = null;
         var _loc5_:Array = null;
         var _loc6_:Array = null;
         var _loc7_:String = null;
         var _loc8_:int = 0;
         var _loc9_:int = 0;
         var _loc10_:int = 0;
         var _loc11_:Object = null;
         var _loc2_:Array = [];
         for each(classInfo in sortedClasses)
         {
            _loc5_ = [];
            _loc6_ = [];
            _loc7_ = param1["Component"];
            _loc7_ = _loc7_.replace("{packageName}",thisPackagePath);
            _loc7_ = _loc7_.split("{className}").join(classInfo.encodedClassName);
            _loc7_ = _loc7_.replace("{componentName}","fairygui." + (!!classInfo.customSuperClassName?classInfo.customSuperClassName:classInfo.superClassName));
            _loc7_ = _loc7_.replace("{uiPath}","ui://" + publishData.targetUIPackage.id + classInfo.classId);
            _loc7_ = _loc7_.replace("{createInstance}","\t\t\treturn <" + classInfo.encodedClassName + "><any>(fairygui.UIPackage.createObject(\"" + publishData.targetUIPackage.name + "\",\"" + classInfo.className + "\"));");
            _loc7_ = _loc7_.split("{uiPkgName}").join(publishData.targetUIPackage.name);
            _loc7_ = _loc7_.split("{uiResName}").join(classInfo.className);
            _loc8_ = 0;
            _loc9_ = 0;
            _loc10_ = 0;
            for each(_loc11_ in classInfo.members)
            {
               if(_loc11_.type == "Controller")
               {
                  if(!_loc11_.ignored)
                  {
                     if(settings.getMemberByName)
                     {
                        _loc5_.push("\t\t\tthis." + _loc11_.name + " = this.getController(\"" + _loc11_.originalName + "\");");
                     }
                     else
                     {
                        _loc5_.push("\t\t\tthis." + _loc11_.name + " = this.getControllerAt(" + _loc9_ + ");");
                     }
                  }
                  _loc9_++;
               }
               else if(_loc11_.type == "Transition")
               {
                  if(!_loc11_.ignored)
                  {
                     if(settings.getMemberByName)
                     {
                        _loc5_.push("\t\t\tthis." + _loc11_.name + " = this.getTransition(\"" + _loc11_.originalName + "\");");
                     }
                     else
                     {
                        _loc5_.push("\t\t\tthis." + _loc11_.name + " = this.getTransitionAt(" + _loc10_ + ");");
                     }
                  }
                  _loc10_++;
               }
               else
               {
                  if(!_loc11_.ignored)
                  {
                     if(settings.getMemberByName)
                     {
                        _loc5_.push("\t\t\tthis." + _loc11_.name + " = <" + GenCodeUtils.translateClassName(_loc11_.type) + "><any>(this.getChild(\"" + _loc11_.originalName + "\"));");
                     }
                     else
                     {
                        _loc5_.push("\t\t\tthis." + _loc11_.name + " = <" + GenCodeUtils.translateClassName(_loc11_.type) + "><any>(this.getChildAt(" + _loc8_ + "));");
                     }
                  }
                  _loc8_++;
               }
               if(!_loc11_.ignored)
               {
                  _loc6_.push("\t\tpublic " + _loc11_.name + ":" + GenCodeUtils.translateClassName(_loc11_.type) + ";");
               }
            }
            _loc7_ = _loc7_.replace("{variable}",_loc6_.join("\r\n"));
            _loc7_ = _loc7_.replace("{content}",_loc5_.join("\r\n"));
            _loc2_.push("\t\t\tfairygui.UIObjectFactory.setPackageItemExtension(" + classInfo.encodedClassName + ".URL, " + classInfo.encodedClassName + ");");
            UtilsFile.saveString(new File(thisPackageFolder.nativePath + File.separator + classInfo.encodedClassName + ".ts"),GenCodeUtils.FILE_MARK + "\n\n" + _loc7_);
         }
         _loc3_ = thisPackageName + "Binder";
         _loc4_ = param1["Binder"];
         _loc4_ = _loc4_.replace("{packageName}",thisPackagePath);
         _loc4_ = _loc4_.split("{className}").join(_loc3_);
         _loc4_ = _loc4_.replace("{bindContent}",_loc2_.join("\r\n"));
         UtilsFile.saveString(new File(thisPackageFolder.nativePath + File.separator + _loc3_ + ".ts"),GenCodeUtils.FILE_MARK + "\n\n" + _loc4_);
         stepCallback.callOnSuccess();
      }
   }
}
